﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DacSanMienTayOBJ;
using System.Text;

public partial class Proccess_LockAndUnclockGroupProduct : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GroupProductLockAdnUnclock();
    }
    private void GroupProductLockAdnUnclock()
    {
        try
        {
            int groupID = int.Parse(Request["groupID"]);
            string typeLock = Request["typeLock"];
            string groupName = Request["groupName"];
            string keyword = Request["keyword"];
            int vt = int.Parse(Request["vt"]);
            int visible = int.Parse(Request["visible"]);
            StringBuilder builder = new StringBuilder();
            if (typeLock == "lock")
            {
                bool rs = GroupProductBusiness.UpdateGroupProductVisible(groupID, 0, ConnectionType.AdminConnection);
                if (rs)
                {
                    string status = "Inactive";
                    visible = 0;
                    builder.Append("<td><label id=\"lbGroupID" + vt + "\" title=\"" + groupID + "\">" + groupID + "</label></td>");
                    builder.Append("<td><input type=\"text\" style=\"width:350px\" value=\"" + groupName + "\" id=\"txtName" + vt + "\" /> </td>");
                    builder.Append("   <td><textarea type=\"text\" style=\"width:350px\" id=\"txtKeywordUpdate" + vt + "\" cols=\"1\" rows=\"2\" >" + keyword + "</textarea> </td>");
                    builder.Append("<td>" + status + "</td>");
                    builder.Append("<td><input type=\"button\" value=\"Cập nhật\" onclick=\"UpdateGroupProduct('" + groupID + "','" + vt + "','" + visible + "')\" /> </td>");
                    builder.Append("<td>");

                    builder.Append("<input type=\"button\" value=\"UnLock\" onclick=\"LockAndUnclockGroupProduct('" + groupID + "','" + vt + "','unlock','" + visible + "')\" />");

                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("errorlock");
                }
                Response.End();
            }
            else if (typeLock == "unlock")
            {
                bool rs = GroupProductBusiness.UpdateGroupProductVisible(groupID, 1, ConnectionType.AdminConnection);
                if (rs)
                {
                    string status = "Active";
                    visible = 1;
                    builder.Append("<td><label id=\"lbGroupID" + vt + "\" title=\"" + groupID + "\">" + groupID + "</label></td>");
                    builder.Append("<td><input type=\"text\" style=\"width:350px\" value=\"" + groupName + "\" id=\"txtName" + vt + "\" /> </td>");
                    builder.Append("   <td><textarea type=\"text\" style=\"width:350px\" id=\"txtKeywordUpdate" + vt + "\" cols=\"1\" rows=\"2\" >" + keyword + "</textarea> </td>");
                    builder.Append("<td>" + status + "</td>");
                    builder.Append("<td><input type=\"button\" value=\"Cập nhật\" onclick=\"UpdateGroupProduct('" + groupID + "','" + vt + "','" + visible + "')\" /> </td>");
                    builder.Append("<td>");

                    builder.Append("<input type=\"button\" value=\"Lock\" onclick=\"LockAndUnclockGroupProduct('" + groupID + "','" + vt + "','lock','" + visible + "')\" />");

                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("errorunlock");
                }
                Response.End();
            }

        }
        catch
        {

        }
    }
}